package com.fyh.mapper;

import com.fyh.entity.chat.SimpleContact;
import com.fyh.entity.user.SimpleCandidate;
import com.fyh.entity.user.User;
import com.fyh.entity.user.UserLogin;
import com.fyh.entity.user.Vitae;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 登录判断
     * @param userLogin
     * @return
     */
    UserLogin login(UserLogin userLogin);

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    User selectByUsername(String username);

    /**
     * 注册
     * @param user
     */
     void insert(User user);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    User selectById(Long id);

    /**
     * 修改用户信息
     * @param user
     */
    void update(User user);

    /**
     * 根据id查询用户昵称
     * @param id
     * @return
     */
    String selectNicknameById(Long id);

    /**
     * 根据userId查询用户偏好地址
     * @param userId
     * @return
     */
    @Select("select address from preferred_address where user_id = #{userId}")
    List<String> selectPreferredAddresses(Long userId);

    /**
     * 删除用户偏好地址
     */
    @Delete("delete from preferred_address where user_id = #{userId}")
    void deletePreferredAddresses(Long userId);

    /**
     * 添加用户偏好地址
     */
    @Insert("insert into preferred_address (user_id, address) values (#{userId}, #{address})")
    void insertPreferredAddresses(@Param("userId") Long userId, @Param("address") String address);

    /**
     * 修改用户简历
     */
    void updateVitae(Vitae vitae);

    /**
     * 获取求职者基础信息
     */
    @Select("select user_id, nickname, age, sex, avatar_path from users where user_id = #{candidateId}")
    SimpleCandidate getSimpleCandidate(Long candidateId);



    /**
     * 登出
     */
    @Update("update users set status = 0 where user_id = #{userId}")
    void logout(Long userId);

    /**
     * 登录修改用户状态
     */
    @Update("update users set status = 1 where user_id = #{userId}")
    void updateStatus(Long userId);

    /**
     * 获取联系人头像路径
     */
    @Select("select avatar_path, status from users where user_id = #{userId}")
    SimpleContact getContactAvatarPath(Long userId);
}
